package net.janeluo.rs.service;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import net.janeluo.rs.entity.RS_Orders;

import org.apache.commons.lang.StringUtils;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.sql.Criteria;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.service.Service;

/**
 * 订单列表业务类
 * 
 * @author DLK)JaneLuo
 * @version 1.0.0
 */
@IocBean(fields = { "dao" })
public class OrdersListService extends Service {
    private static final Log log = Logs.getLog(OrdersListService.class);

    public OrdersListService() {
        super();
    }

    public OrdersListService(Dao dao) {
        super(dao);
    }
    
    /**
     * 订单列表查询
     * 
     * @return
     */
    public Map<String, List<RS_Orders>> getOrderList(String date) {
        log.debug("============= 我的订单查询处理开始 =============");

        Map<String, List<RS_Orders>> orderMap= new LinkedHashMap<String, List<RS_Orders>>();
        
        Criteria cri = Cnd.cri();
        if (StringUtils.isNotEmpty(date)) {
            cri.where().andLike("orderTime", date);
        }
        
        cri.getOrderBy().asc("mid");
        
        // 订单列表
        List<RS_Orders> list = dao().fetchLinks(dao().query(RS_Orders.class, cri), "menu");
        for (RS_Orders rs_Orders : list) {
            String sname = rs_Orders.getMenu().getSname();
            List<RS_Orders> orderLst = orderMap.get(sname);
            if (orderLst == null) {
                orderLst = new LinkedList<RS_Orders>();
            }
            orderLst.add(rs_Orders);
            orderMap.put(sname, orderLst);
        }
        
        log.debug("============= 我的订单查询处理结束 =============");
        return orderMap;
    }
}
